<?php
class item_createforum extends template_item
{
	var $default_name = "Create a Forum";
	var $default_description = "Create a forum for yourself.";
	
	var $allow_multiple = 1;
	
	var $item_config = array();
	var $forums = array();
	
	function load_item(&$item)
	{
		parent::load_item($item);
		
		if($item['item_config'] || $item['item_id'] != 0)
		{
			$this->item_config = unserialize($item['item_config']);
		}
		else
		{
			$this->item_config['parent_forum'] = 0;
			$this->item_config['set_password'] = 1;
			$this->item_config['allow_html'] = 0;
			$this->item_config['allow_bbcode'] = 1;
			$this->item_config['allow_quick_reply'] = 1;
			$this->item_config['allow_polls'] = 1;
			$this->item_config['allow_poll_bump'] = 0;
			$this->item_config['allow_rating'] = 0;
			$this->item_config['allow_post_inc'] = 1;
			$this->item_config['prune'] = 100;
			$this->item_config['sort_key'] = 'last_post';
			$this->item_config['sort_order'] = 'Z-A';
			$this->item_config['sort_filter'] = 'all';
			$this->item_config['edit_post'] = 1;
			$this->item_config['edit_title'] = 1;
			$this->item_config['delete_post'] = 0;
			$this->item_config['delete_topic'] = 0;
			$this->item_config['un_lock_topic'] = 1;
			$this->item_config['un_pin_topic'] = 1;
			$this->item_config['merge_topic'] = 0;
			$this->item_config['set_open_time'] = 1;
			$this->item_config['set_close_time'] = 1;
			$this->item_config['show_forum'] = array('*');
			$this->item_config['read_topic'] = array('*');
			$this->item_config['reply_topic'] = array('*');
			$this->item_config['start_topic'] = array('*');
			$this->item_config['upload'] = array('*');
			$this->item_config['download'] = array('*');
			$this->item_config['move_deleted'] = 0;
			$this->item_config['lasting'] = 21;
			$this->item_config['time_unit'] = 86400;
			$this->item_config['market_reply'] = 0;
			$this->item_config['market_reply_amount'] = 0;
			$this->item_config['market_topic'] = 0;
			$this->item_config['market_topic_amount'] = 0;
		}
		
		$this->forums = $item['settings'] ? unserialize($item['settings']) : array();
		if(count($this->forums) && $this->ipsclass->input['request_method'] != 'post' && IPB_THIS_SCRIPT == 'public')
		{
			$update = 0;
			$forums = array();
			$time = time();
			foreach($this->forums as $f_id => $end)
			{
				if(!$update && $end && $end < $time)
				{
					if($this->item_config['move_deleted'])
					{
						$this->ipsclass->DB->do_update( 'topics', array( 'forum_id' => $this->item_config['move_deleted'] ), 'forum_id='.$f_id );
						$this->ipsclass->DB->do_update( 'polls' , array( 'forum_id' => $this->item_config['move_deleted'] ), 'forum_id='.$f_id );
						$this->ipsclass->DB->do_update( 'voters', array( 'forum_id' => $this->item_config['move_deleted'] ), 'forum_id='.$f_id );
					}
					else
					{
						$this->ipsclass->DB->do_delete( 'topics', 'forum_id='.$f_id );
						$this->ipsclass->DB->do_delete( 'polls' , 'forum_id='.$f_id );
						$this->ipsclass->DB->do_delete( 'voters', 'forum_id='.$f_id );
					}
					$this->ipsclass->DB->do_delete( 'forums', 'id='.$f_id );
					$this->ipsclass->DB->do_delete( 'moderators', 'forum_id='.$f_id );
					$this->ipsclass->DB->do_delete( 'forum_tracker', 'forum_id='.$f_id );
					$this->ipsclass->DB->do_update( 'forums', array( 'parent_id' => $this->item_config['move_deleted'] ), "parent_id=".$f_id ); // So there is not any lost forums
					$update = 1;
					continue;
				}
				$forums[$f_id] = $end;
			}
			if($update)
			{
				$this->ipsclass->DB->do_update('market_items',array('settings'=>serialize($forums)),"item_id=".$this->item['item_id']);
				$this->ipsclass->market_class->cache_items();
				$this->ipsclass->update_forum_cache();
				$this->ipsclass->market_class->redirect("",$this->ipsclass->base_url.$_SERVER['QUERY_STRING'],array('instant'=>1,'url'=>1)); // No cache conflict
			}
		}
	}
	
	function admin_form()
	{
		$this->ipsclass->forums->forums_init();
		
		require_once(ROOT_PATH.'sources/lib/admin_forum_functions.php');
		
		$forumfunc = new admin_forum_functions();
		$forumfunc->ipsclass =& $this->ipsclass;
		$forums = $forumfunc->ad_forums_forum_list(1);
		$flist = array_merge(array(array(0,'Permanently Remove All Posts')),$forums);
		
		$perm_masks   = array();
		$perm_masks[] = array('*','Global Permissions (All current and future sets)');
		$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'forum_perms' ) );
		$this->ipsclass->DB->simple_exec();
		while ( $r = $this->ipsclass->DB->fetch_row() )
		{
			$perm_masks[] = array( $r['perm_id'], $r['perm_name'] );
		}
		
		$dd_prune    = array( 
							 0 => array( 1, 'Today' ),
							 1 => array( 5, 'Last 5 days'  ),
							 2 => array( 7, 'Last 7 days'  ),
							 3 => array( 10, 'Last 10 days' ),
							 4 => array( 15, 'Last 15 days' ),
							 5 => array( 20, 'Last 20 days' ),
							 6 => array( 25, 'Last 25 days' ),
							 7 => array( 30, 'Last 30 days' ),
							 8 => array( 60, 'Last 60 days' ),
							 9 => array( 90, 'Last 90 days' ),
							 10=> array( 100,'Show All'     ),
							);
		
		$dd_order    = array( 
							 0 => array( 'last_post', 'Date of the last post' ),
							 1 => array( 'title'    , 'Topic Title' ),
							 2 => array( 'starter_name', 'Topic Starters Name' ),
							 3 => array( 'posts'    , 'Topic Posts' ),
							 4 => array( 'views'    , 'Topic Views' ),
							 5 => array( 'start_date', 'Date topic started' ),
							 6 => array( 'last_poster_name'   , 'Name of the last poster' )
							);
																							
																							
																							
		$dd_by       = array( 
							 0 => array( 'Z-A', 'Descending (Z - A, 0 - 10)' ),
							 1 => array( 'A-Z', 'Ascending (A - Z, 10 - 0)'  )
							);
							
		$dd_filter	 = array(
							 0 => array( 'all', 	'All Topics' ),
							 1 => array( 'open', 	'Open Topics' ),
							 2 => array( 'hot',		'Hot Topics' ),
							 3 => array( 'poll',	'Polls' ),
							 4 => array( 'locked',	'Locked Topics' ),
							 5 => array( 'moved',	'Moved Topics' ),
							 6 => array( 'istarted', 'Topics Reader Started' ),
							 7 => array( 'ireplied', 'Topics Reader Replied' ),
							);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>How long does this forum lasts?</b><br />Input 0 for unlimited time.",
															$this->ipsclass->adskin->form_simple_input("item[".$this->item['item_id']."][lasting]", $this->item_config['lasting']).$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][time_unit]", array(array(86400,'Days'),array(604800,'Weeks')), $this->item_config['time_unit']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>What is the forum parent for the temporary?</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][parent_forum]", $forums, $this->item_config['parent_forum']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to set a password to the forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][set_password]", $this->item_config['set_password']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable HTML Posting</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_html]", $this->item_config['allow_html']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable BBCode Posting</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_bbcode]", $this->item_config['allow_bbcode']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable Quick Reply</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_quick_reply]", $this->item_config['allow_quick_reply']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable Polls (per user group option)</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_polls]", $this->item_config['allow_polls']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable Poll Bump</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_poll_bump]", $this->item_config['allow_poll_bump']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable Topic Rating (per user group option)</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_rating]", $this->item_config['allow_rating']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Enable Post Count Incrementation</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][allow_post_inc]", $this->item_config['allow_post_inc']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Default date cut off for topic display</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][prune]", $dd_prune, $this->item_config['prune']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Default sort key</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][sort_key]", $dd_order, $this->item_config['sort_key']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Default sort order</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][sort_order]", $dd_by, $this->item_config['sort_order']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Default sort filter</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][sort_filter]", $dd_filter, $this->item_config['sort_filter']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Should this forum have different money gained per topic reply than the global setting?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][market_reply]",$this->item_config['market_reply']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>If so, amount of to gain per topic reply?</b>",
															$this->ipsclass->adskin->form_simple_input("item[".$this->item['item_id']."][market_reply_amount]",$this->item_config['market_reply_amount']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Should this forum have different money gained per new topic than the global setting?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][market_topic]",$this->item_config['market_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>If so, amount of to gain per new topic?</b>",
															$this->ipsclass->adskin->form_simple_input("item[".$this->item['item_id']."][market_topic_amount]",$this->item_config['market_topic_amount']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to edit other polls/posts in that forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][edit_post]", $this->item_config['edit_post']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to edit other topic titles in that forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][edit_title]", $this->item_config['edit_title']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to delete other posts in that forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][delete_post]", $this->item_config['delete_post']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to delete other topics in that forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][un_lock_topic]", $this->item_config['un_lock_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to pin and unpin topics in that forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][un_pin_topic]", $this->item_config['un_pin_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to split and merge topics in that forum?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][merge_topic]", $this->item_config['merge_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to set topic open time?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][set_open_time]", $this->item_config['set_open_time']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Allow the member to set topic close time?</b>",
															$this->ipsclass->adskin->form_yes_no("item[".$this->item['item_id']."][set_close_time]", $this->item_config['set_close_time']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Show Forum Permission Access Level</b>",
															$this->ipsclass->adskin->form_multiselect("item[".$this->item['item_id']."][show_forum][]", $perm_masks, $this->item_config['show_forum']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Read Topic Permission Access Level</b>",
															$this->ipsclass->adskin->form_multiselect("item[".$this->item['item_id']."][read_topic][]", $perm_masks, $this->item_config['read_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Reply Topic Permission Access Level</b>",
															$this->ipsclass->adskin->form_multiselect("item[".$this->item['item_id']."][reply_topic][]", $perm_masks, $this->item_config['reply_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Start Topic Permission Access Level</b>",
															$this->ipsclass->adskin->form_multiselect("item[".$this->item['item_id']."][start_topic][]", $perm_masks, $this->item_config['start_topic']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Upload Permission Access Level</b>",
															$this->ipsclass->adskin->form_multiselect("item[".$this->item['item_id']."][upload][]", $perm_masks, $this->item_config['upload']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Download Permission Access Level</b>",
															$this->ipsclass->adskin->form_multiselect("item[".$this->item['item_id']."][download][]", $perm_masks, $this->item_config['download']),
													)	);
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>What fourm to move all posts when this forum is removed?</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][move_deleted]", $flist, $this->item_config['move_deleted']),
													)	);
		
		return $html;
	}
	
	function admin_save(&$item_info, $input)
	{
		$save = array();
		$save['parent_forum'] = intval($input['parent_forum']);
		$save['set_password'] = $input['set_password'] & 1;
		$save['allow_html'] = $input['allow_html'] & 1;
		$save['allow_bbcode'] = $input['allow_bbcode'] & 1;
		$save['allow_quick_reply'] = $input['allow_quick_reply'] & 1;
		$save['allow_polls'] = $input['allow_polls'] & 1;
		$save['allow_poll_bump'] = $input['allow_poll_bump'] & 1;
		$save['allow_rating'] = $input['allow_rating'] & 1;
		$save['allow_post_inc'] = $input['allow_post_inc'] & 1;
		$save['prune'] = $input['prune'];
		$save['sort_key'] = $input['sort_key'];
		$save['sort_order'] = $input['sort_order'];
		$save['sort_filter'] = $input['sort_filter'];
		$save['edit_post'] = $input['edit_post'] & 1;
		$save['edit_title'] = $input['edit_title'] & 1;
		$save['delete_post'] = $input['delete_post'] & 1;
		$save['delete_topic'] = $input['delete_topic'] & 1;
		$save['un_lock_topic'] = $input['un_lock_topic'] & 1;
		$save['un_pin_topic'] = $input['un_pin_topic'] & 1;
		$save['merge_topic'] = $input['merge_topic'] & 1;
		$save['set_open_time'] = $input['set_open_time'] & 1;
		$save['set_close_time'] = $input['set_close_time'] & 1;
		$save['show_forum'] = !is_array($input['show_forum']) ? array() : (in_array('*',$input['show_forum']) ? array('*') : $input['show_forum']);
		$save['read_topic'] = !is_array($input['read_topic']) ? array() : (in_array('*',$input['read_topic']) ? array('*') : $input['read_topic']);
		$save['reply_topic'] = !is_array($input['reply_topic']) ? array() : (in_array('*',$input['reply_topic']) ? array('*') : $input['reply_topic']);
		$save['start_topic'] = !is_array($input['start_topic']) ? array() : (in_array('*',$input['start_topic']) ? array('*') : $input['start_topic']);
		$save['upload'] = !is_array($input['upload']) ? array() : (in_array('*',$input['upload']) ? array('*') : $input['upload']);
		$save['download'] = !is_array($input['download']) ? array() : (in_array('*',$input['download']) ? array('*') : $input['download']);
		$save['move_deleted'] = intval($input['move_deleted']);
		$save['lasting'] = max(0,intval($input['lasting']));
		$save['time_unit'] = $input['time_unit'] == 604800 ? 604800 : 86400;
		$save['market_reply'] = $input['market_reply'] & 1;
		$save['market_reply_amount'] = $this->ipsclass->numbers->parse_input_number($input['market_reply_amount'],'int');
		$save['market_topic'] = $input['market_topic'] & 1;
		$save['market_topic_amount'] = $this->ipsclass->numbers->parse_input_number($input['market_topic_amount'],'int');
		
		$item_info['item_config'] = serialize($save);
	}
	
	function public_use_form($inventory_ids = array())
	{
		$this->ipsclass->load_language('lang_market_items');
		
 		$this->ipsclass->han_editor->remove_side_panel = 1;
 		$this->ipsclass->han_editor->remove_emoticons  = 1;
        
        $editor = $this->ipsclass->han_editor->show_editor( '', 'forum_desc' );
        
		$hidden_fields = $this->_get_hidden_fields($inventory_ids);
		
		return "
<div class='formsubtitle'>{$this->ipsclass->lang['create_a_forum']}</div>
<form action='{$this->base_url}' method='post' onsubmit='return ValidateForm()'>
{$hidden_fields}
	<table class='ipbtable' cellspacing='0' cellpadding='0'>
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['forum_name']}</b>
			</td>
			<td class='row2' align='right'>
				<input type='input' name='forum_name' value='' size='30' class='forminput' />
			</td>
		</tr>
		<tr>
			<td class='darkrow1' align='left' colspan='2'>
				{$this->ipsclass->lang['forum_description']}
			</td>
		</tr>
		<tr>
			<td class='row1' align='left' colspan='2'>
{$editor}
			</td>
		</tr>".($this->item_config['set_password'] ? "
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['forum_password']}</b><br />{$this->ipsclass->lang['blank_password']}
			</td>
			<td class='row2' align='right'>
				<input type='input' name='forum_pass' value='' size='30' class='forminput' />
			</td>
		</tr>" : "")."
		<tr>
			<td class='darkrow1' align='center' colspan='2'>
				<input type='submit' name='item_used' value='{$this->ipsclass->lang['create_forum']}' class='forminput' />
			</td>
		</tr>
	</table>
</form>";
	}
	
	function input_done()
	{
		return isset($this->ipsclass->input['forum_name']) && isset($this->ipsclass->input['forum_desc']) && isset($this->ipsclass->input['item_used']);
	}
	
	function public_use_item($inventory_ids = array()) 
	{
		$this->ipsclass->load_language('lang_market_items');
		
		$this->ipsclass->input['forum_desc'] = $this->ipsclass->han_editor->process_raw_post('forum_desc');
		$this->ipsclass->parser->parse_smilies     = 0;
		$this->ipsclass->parser->parse_html        = intval($this->ipsclass->vars['sig_allow_html']);
		$this->ipsclass->parser->parse_bbcode      = intval($this->ipsclass->vars['sig_allow_ibc']);
		$this->ipsclass->parser->parsing_signature = 1;
		$this->ipsclass->input['forum_desc']       = $this->ipsclass->parser->bad_words( $this->ipsclass->parser->pre_display_parse( $this->ipsclass->parser->pre_db_parse( $this->ipsclass->input['forum_desc'] ) ) );
		if ($this->ipsclass->parser->error != "")
		{
			$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => $this->ipsclass->parser->error) );
		}
		
		$this->ipsclass->input['forum_name']       = trim( $this->ipsclass->parser->bad_words( $this->ipsclass->input['forum_name'] ) );
		if ($this->ipsclass->parser->error != "")
		{
			$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => $this->ipsclass->parser->error) );
		}
		if(strlen($this->ipsclass->input['forum_name']) > 128 || !$this->ipsclass->input['forum_name'])
		{
			$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'forum_name_error') );
		}
		
		if(!$this->item_config['set_password'])
		{
			$this->ipsclass->input['forum_pass'] = '';
		}
		
		$row = $this->ipsclass->DB->build_and_exec_query(array('select'=>'MAX(position) as top_pos','from'=>'forums','where'=>"parent_id=".$this->item_config['parent_forum']));
		$last = $this->ipsclass->DB->build_and_exec_query(array('select'=>'MAX(id) as top_id','from'=>'forums'));
		
		$permissions = array(
								'start_perms' => implode(",",$this->item_config['start_topic']),
								'reply_perms' => implode(",",$this->item_config['reply_topic']),
								'read_perms' => implode(",",$this->item_config['read_topic']),
								'upload_perms' => implode(",",$this->item_config['upload']),
								'download_perms' => implode(",",$this->item_config['download']),
								'show_perms' => implode(",",$this->item_config['show_forum']),
							);
		
		$forum = array(
							'id' => $last['top_id'] + 1,
							'topics' => 0,
							'posts' => 0,
							'last_post' => 0,
							'last_poster_id' => 0,
							'last_poster_name' => '',
							'name' => $this->ipsclass->input['forum_name'],
							'description' => $this->ipsclass->input['forum_desc'],
							'position' => $row['top_pos'] + 1,
							'use_ibc' => $this->item_config['allow_bbcode'],
							'use_html' => $this->item_config['allow_html'],
							'status' => 1,
							'password' => $this->ipsclass->input['forum_pass'],
							'password_override' => '',
							'last_title' => '',
							'last_id' => 0,
							'sort_key' => $this->item_config['sort_key'],
							'sort_order' => $this->item_config['sort_order'],
							'prune' => $this->item_config['prune'],
							'topicfilter' => $this->item_config['sort_filter'],
							'show_rules ' => 0,
							'preview_posts ' => 0,
							'allow_poll' => $this->item_config['allow_polls'],
							'allow_pollbump' => $this->item_config['allow_poll_bump'],
							'inc_postcount' => $this->item_config['allow_post_inc'],
							'skin_id' => 0,
							'parent_id' => $this->item_config['parent_forum'],
							'quick_reply' => $this->item_config['parent_forum'],
							'redirect_url' => '',
							'redirect_on' => 0,
							'redirect_hits' => 0,
							'redirect_loc' => '',
							'rules_title' => '',
							'rules_text' => '',
							'topic_mm_id' => '',
							'sub_can_post' => 1,
							'permission_custom_error' => '',
							'permission_array' => addslashes(serialize($permissions)),
							'permission_showtopic' => 0,
							'queued_topics' => 0,
							'queued_posts' => 0,
							'forum_allow_rating' => $this->item_config['allow_rating'],
							'forum_last_deletion' => 0,
							'newest_title' => '',
							'newest_id' => 0,
							'market_reply' => $this->item_config['market_reply'],
							'market_reply_amount' => $this->item_config['market_reply_amount'],
							'market_topic' => $this->item_config['market_topic'],
							'market_topic_amount' => $this->item_config['market_topic_amount'],
						);
		
		$mod = array(
						'forum_id' => $forum['id'],
						'member_name' => $this->ipsclass->member['name'],
						'member_id' => $this->ipsclass->member['id'],
						'edit_post' => $this->item_config['edit_post'],
						'edit_topic' => $this->item_config['edit_topic'],
						'delete_post' => $this->item_config['delete_post'],
						'delete_topic' => $this->item_config['delete_topic'],
						'view_ip' => 0,
						'open_topic' => $this->item_config['un_lock_topic'],
						'close_topic' => $this->item_config['un_lock_topic'],
						'mass_move' => 0,
						'mass_prune' => 0,
						'move_topic' => 0,
						'pin_topic' => $this->item_config['un_pin_topic'],
						'unpin_topic' => $this->item_config['un_pin_topic'],
						'post_q' => 0,
						'topic_q' => 0,
						'allow_warn' => 0,
						'edit_user' => 0,
						'is_group' => 0,
						'group_id' => 0,
						'group_name' => '',
						'split_merge' => $this->item_config['merge_topic'],
						'can_mm' => 0,
						'mod_can_set_open_time' => $this->item_config['set_open_time'],
						'mod_can_set_close_time' => $this->item_config['set_close_time'],
					);
		
		$this->ipsclass->DB->do_insert('forums',$forum);
		$this->ipsclass->DB->do_insert('moderators',$mod);
		
		if($this->item_config['lasting'])
		{
			$this->forums[$forum['id']] = time() + $this->item_config['lasting'] * $this->item_config['time_unit'];
		}
		else
		{
			$this->forums[$forum['id']] = 0;
		}
		$this->ipsclass->DB->do_update('market_items',array('settings'=>serialize($this->forums)),"item_id=".$this->item['item_id']);
		
		$this->ipsclass->market_class->cache_items();
		$this->ipsclass->update_forum_cache();
		require_once( ROOT_PATH.'sources/action_admin/moderator.php' );
		$this->mod           =  new ad_moderator();
		$this->mod->ipsclass =& $this->ipsclass;
		
		$this->mod->rebuild_moderator_cache();
		
		$this->delete_items($inventory_ids);
		
		$inv_id = reset($inventory_ids);
		$this->_write_log($inv_id, "Created forum ".$this->ipsclass->input['forum_name']);
		
		$this->ipsclass->market_class->redirect('forum_created',$this->ipsclass->base_url."showforum=".$forum['id'],array('url'=>1));
	}
}
?>